import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
// import eslintPlugin from 'vite-plugin-eslint';
import checker from 'vite-plugin-checker';

// https://vitejs.dev/config/
export default defineConfig({
	plugins: [
		react(),
		// eslintPlugin({
		// 	include: ['src/**/*.ts', 'src/**/*.tsx', 'src/*.ts', 'src/*.tsx']
		// }),
		checker({ typescript: true, terminal: true })
	],
	server: {
		host: true,
		port: 8088,
		proxy: {
			'/api': {
				// target: 'https://cms.coderwyf.com',
				// target: 'http://192.168.0.200/api',
				// target: 'http://localhost:3000',
				target: 'http://dev-host/api',
				changeOrigin: true,
				rewrite: (path) => path.replace(/^\/api/, '')
			}
		}
	},
	resolve: {
		// 配置路径别名
		alias: {
			'@': '/src'
		}
	},
	build: {
		rollupOptions: {
			output: {
				format: 'es',
				entryFileNames: 'js/[name]-[hash].js',
				chunkFileNames: 'js/[name]-[hash].js',
				// assetFileNames: '[ext]/[name]-[hash].[ext]'
				assetFileNames: (assetInfo) => {
					if (assetInfo.name.endsWith('.css')) {
						return 'css/[name]-[hash].css';
					}
					const imgExts = ['.png', '.jpg', '.jpeg', '.webp', '.svg', '.gif', '.ico'];
					if (imgExts.some((ext) => assetInfo.name.endsWith(ext))) {
						return 'images/[name]-[hash].[ext]';
					}
					return '[ext]/[name]-[hash].[ext]';
				}
			}
		}
	}
});
